package top.jiangqiang.qianyi.common.base.http;

import org.springframework.http.HttpStatus;
import top.jiangqiang.qianyi.common.constants.http.Error500Status;
import top.jiangqiang.qianyi.common.exception.Error500Exception;

/**
 * 通用状态码接口
 */
public interface BaseStatus {

    /**
     * @return 编码
     */
    int getCode();

    /**
     * return 消息
     */
    String getMessage();

    /**
     * @return 业务编码
     */
    default int getBusinessCode() {
        if (getCode() > 100000) {
            throw new Error500Exception(Error500Status.INTERNAL_SERVER_ERROR);
        }
        return getRawStatusCode() * 100000 + getCode();
    }

    /**
     * @return http状态码的code
     */
    int getRawStatusCode();

    /**
     * @return http状态码
     */
    HttpStatus getHttpStatus();

}
